//
//  SAPersonalInfomationViewController.m
//  SunOn
//
//  Created by RazeenCheng on 2017/5/3.
//  Copyright © 2017年 NeoZhang. All rights reserved.
//

#import "SAPersonalInfomationViewController.h"
#import "SAPersonalInfomationHeaderCell.h"
#import "SAPersonalInfomationSectionCell.h"

@interface SAPersonalInfomationViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView;


@end

@implementation SAPersonalInfomationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    [self prepareForNavigation];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBarHidden = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Navigation
- (void)prepareForNavigation
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 40, 20);
    [button setTitle:@"编辑" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor colorWithHexString:@"000000"] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:16];
    [button addTarget:self action:@selector(rightButtonAction) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.rightBarButtonItem = rightButtonItem;
}

- (void)rightButtonAction
{
    
}



#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger row = indexPath.row;
    
    if (row == 0) {
        SAPersonalInfomationHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SAPersonalInfomationHeaderCell" forIndexPath:indexPath];
        return cell;
    } else if (row == 2) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SeparatorCell" forIndexPath:indexPath];
        return cell;
    } else {
        SAPersonalInfomationSectionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SAPersonalInfomationSectionCell" forIndexPath:indexPath];
        [cell configCellWithRow:row];
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger row = indexPath.row;
    
    if (row == 0) {
        return 86;
    } else if (row == 2) {
        return 10;
    } else {
        return 56;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

@end
